<template>
	<view :class="[primarySize()]">
		<view class="container">
			<view style="margin-top:30rpx;" v-for="(item,index) in list" @click="goRedirect" :data-index="index">
				<view class="tc">
					<text class="time_part">{{formatDatetime(item.createtime,'yyyy年mm月dd日 hh:ii')}}</text>
				</view>
				<view class="message_con">
					<view class="fs32 col0">{{item.title||item.name}}</view>
					<view class="fs24 col9 pt20">{{formatDatetime(item.createtime, 'mm月dd日')}}</view>
					<view class="message_text">{{item.content}}</view>
				</view>
			</view>
			<view class="nothing" v-if="listMore.nothing">
				<image src="@/static/public/icon_nothing.png" mode="aspectFit"></image>
				<text>暂无消息</text>
			</view>
			<view class="g-btn3-wrap" v-else>
				<view class="g-btn3">{{listMore.text}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	export default {
		data() {
			return {
				
				type: '',
				list: [],
				listMore: {page: 1},
				url: '',
				listField:''
			}
		},
		onReady() {
			uni.setNavigationBarColor({
				frontColor: '#ffffff',
				backgroundColor: this.primaryColor()
			})
		},
		onLoad(options) {
			
			this.type = options.type;
		    switch (options.type) {
		      case 'personal':
		        this.url = 'xilujob.message/personal_list';
		        this.listField = 'personal_messages';
		        uni.setNavigationBarTitle({title: '个人通知'});
		        break;
		      case 'activity':
		        this.url = 'xilujob.message/activity_list';
		        this.listField = 'activity_messages';
		        uni.setNavigationBarTitle({title: '活动消息'});
		        break;
		      case 'system':
		        this.url = 'xilujob.message/system_list';
		        this.listField = 'system_messages';
		        uni.setNavigationBarTitle({title: '系统消息'});
		        break;
		      default:
		        uni.navigateBack();
		        return;
		    }
		    this.fetch();
		},
		onReachBottom() {
			this.fetch();
		},
		methods: {
			fetch() {
			    this.$util.fetch(this, this.url, {}, 'listMore', 'list', this.listField);
			},
			
			goRedirect(event) {
				if(this.type !=='personal'){
					return;
				}
			    let index = event.currentTarget.dataset.index;
			    let message = this.list[index];
			    switch(message.type) {
			      case 2://简历被查看
			        uni.navigateTo({url: '/pages/user/who_view'});
			        break;
			      case 1://简历投递，通知企业用户
			        uni.navigateTo({url:'/pages/company/resume_application'});
			        break;
			      case 4://面试邀请
			        uni.switchTab({url:'/pages/company/interview_invitations'});
			        break;
			      case 5://面试邀请被用户拒绝
			        uni.switchTab({url:'/pages/company/interview_invitations'});
			        break;
			      case 6://面试邀请被用户同意
			        uni.switchTab({url:'/pages/company/interview_invitations'});
			        break;
			      case 7://面试失败
			        uni.switchTab({url:'/pages/company/interview_invitations'});
			        break;
			      case 8://面试通过
			        uni.switchTab({url:'/pages/company/interview_invitations'});
			        break;
			    }
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding-left: 30rpx;
		padding-right: 30rpx;
	}

	.time_part {
		display: inline-block;
		font-size: 22rpx;
		color: #fff;
		background-color: #D2D4D9;
		padding: 0 10rpx;
		line-height: 42rpx;
		border-radius: 3rpx;
	}

	.message_text {
		line-height: 40rpx;
		
		margin-top: 40rpx;
	}

	.message_con {
		background-color: #fff;
		padding: 30rpx;
		box-sizing: border-box;
		border-radius: 5rpx;
		border: 1rpx solid #ececec;
		margin-top: 20rpx;
	}
</style>